//#include "00.h"

#include "stdafx.h"
#include "tango frenzy.h"

extern int numar_noduri;
int q=1;
nod* headref=NULL;

void freememnod(nod *root)
{
	if (root==NULL) return;
	freememnod(root->left);
	freememnod(root->right);
	free(root);
}

nod* creare_reftree(int left,int right,int h)
{
	int dif;
	nod *crt=NULL;
	if(right-left<=1) return NULL;
	crt=(nod*)malloc(sizeof(nod));
	dif=right-left;
	dif=dif/2;
	crt->info=left+dif;
	crt->d=h;
	crt->preferatstg=q;
	crt->preferatdreapta=0;
	crt->isroot=0;
	crt->maxd=-1;
	crt->mind=-1;
	crt->left=creare_reftree(left,left+dif,h+1);
	crt->right=creare_reftree(left+dif,right,h+1);
	return crt;
}

void iroot_s(nod* root)
{
	if(!root) return;
	iroot_d(root->right);
	iroot_s(root->left);
}

void iroot_d(nod *root)
{
	if (!root) return;
	root->isroot=1;
	iroot_d(root->right);
	iroot_s(root->left);
}



void ref_tree()
{
	freememnod(headref);
	headref=NULL;
	
	q=1;
	headref=creare_reftree(0,numar_noduri+1,0);
	//headref->isroot=1;
	iroot_d(headref);
	tangotree();
	//freetangotree();
}
	